style: Convert border-width to a shorthand
authorBenjamin Otte <otte@redhat.com>
Sat, 21 May 2011 22:10:43 +0000 (00:10 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 22 May 2011 03:56:11 +0000 (05:56 +0200)
Add the corresponding properties it refers to, too:
- border-top-width
- border-left-width
- border-bottom-width
- border-right-width

gtk/gtkcssprovider.c
gtk/gtkstylecontext.c
gtk/gtkstyleproperty.c
gtk/gtkstylepropertyprivate.h

index 6f8cbe4710576d9f7168fac37d6cb03c933215b6..37091b2685ef3687a6dea302774ba90777d38902 100644 (file)
  *         </entry>
  *       </row>
  *       <row>
- *         <entry>border-width</entry>
+ *         <entry>border-top-width</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>border-top-width: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>border-left-width</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>border-left-width: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>border-bottom-width</entry>
  *         <entry>integer</entry>
  *         <entry>#gint</entry>
- *         <entry>border-width: 5;</entry>
+ *         <entry>border-bottom-width: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>border-right-width</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>border-right-width: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>border-width</entry>
+ *         <entry morerows="1">#GtkBorder</entry>
+ *         <entry morerows="1"><literallayout>border-width: 1;
+ * border-width: 1 2;
+ * border-width: 1 2 3;
+ * border-width: 1 2 3 5;</literallayout>
+ *         </entry>
  *       </row>
  *       <row>
  *         <entry>border-radius</entry>
index e96faea2d737540468dd438904d17d037900661a..134a0f27c01b39b928384096eda176cb7b54538a 100644 (file)
@@ -3474,28 +3474,27 @@ gtk_style_context_get_border (GtkStyleContext *context,
 {
   GtkStyleContextPrivate *priv;
   StyleData *data;
-  const GValue *value;
-  GtkBorder *b;
+  int top, left, bottom, right;
 
   g_return_if_fail (border != NULL);
-  *border = fallback_border;
-
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
 
   priv = context->priv;
   g_return_if_fail (priv->widget_path != NULL);
 
   data = style_data_lookup (context);
-  value = _gtk_style_properties_peek_property (data->store,
-                                               "border-width",
-                                               state,
-                                               NULL);
+  gtk_style_properties_get (data->store,
+                            state,
+                            "border-top-width", &top,
+                            "border-left-width", &left,
+                            "border-bottom-width", &bottom,
+                            "border-right-width", &right,
+                            NULL);
 
-  if (value)
-    {
-      b = g_value_get_boxed (value);
-      *border = *b;
-    }
+  border->top = top;
+  border->left = left;
+  border->bottom = bottom;
+  border->right = right;
 }
 
 /**
index 2d6bda681a3d1fd9bde8df4c535fd70fc37ca743..8925ba46cebdbc2516ad461d7269584901b4def1 100644 (file)
@@ -1160,6 +1160,83 @@ bindings_value_to_string (const GValue *value)
   return g_string_free (str, FALSE);
 }
 
+/*** PACKING ***/
+
+static GParameter *
+unpack_border (const GValue *value,
+               guint        *n_params,
+               const char   *top,
+               const char   *left,
+               const char   *bottom,
+               const char   *right)
+{
+  GParameter *parameter = g_new0 (GParameter, 4);
+  GtkBorder *border = g_value_get_boxed (value);
+
+  parameter[0].name = top;
+  g_value_init (&parameter[0].value, G_TYPE_INT);
+  g_value_set_int (&parameter[0].value, border->top);
+  parameter[1].name = left;
+  g_value_init (&parameter[1].value, G_TYPE_INT);
+  g_value_set_int (&parameter[1].value, border->left);
+  parameter[2].name = bottom;
+  g_value_init (&parameter[2].value, G_TYPE_INT);
+  g_value_set_int (&parameter[2].value, border->bottom);
+  parameter[3].name = right;
+  g_value_init (&parameter[3].value, G_TYPE_INT);
+  g_value_set_int (&parameter[3].value, border->right);
+
+  *n_params = 4;
+  return parameter;
+}
+
+static void
+pack_border (GValue             *value,
+             GtkStyleProperties *props,
+             GtkStateFlags       state,
+             const char         *top,
+             const char         *left,
+             const char         *bottom,
+             const char         *right)
+{
+  GtkBorder border;
+  int t, l, b, r;
+
+  gtk_style_properties_get (props,
+                            state,
+                            top, &t,
+                            left, &l,
+                            bottom, &b,
+                            right, &r,
+                            NULL);
+
+  border.top = t;
+  border.left = l;
+  border.bottom = b;
+  border.right = r;
+
+  g_value_set_boxed (value, &border);
+}
+
+static GParameter *
+unpack_border_width (const GValue *value,
+                     guint        *n_params)
+{
+  return unpack_border (value, n_params,
+                        "border-top-width", "border-left-width",
+                        "border-bottom-width", "border-right-width");
+}
+
+static void
+pack_border_width (GValue             *value,
+                   GtkStyleProperties *props,
+                   GtkStateFlags       state)
+{
+  pack_border (value, props, state,
+               "border-top-width", "border-left-width",
+               "border-bottom-width", "border-right-width");
+}
+
 /*** API ***/
 
 static void
@@ -1368,10 +1445,32 @@ gtk_style_property_init (void)
                                                               "Padding",
                                                               GTK_TYPE_BORDER, 0));
   gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("border-width",
+                                          g_param_spec_int ("border-top-width",
+                                                            "border top width",
+                                                            "Border width at top",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("border-left-width",
+                                                            "border left width",
+                                                            "Border width at left",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("border-bottom-width",
+                                                            "border bottom width",
+                                                            "Border width at bottom",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("border-right-width",
+                                                            "border right width",
+                                                            "Border width at right",
+                                                            0, G_MAXINT, 0, 0));
+  _gtk_style_property_register           (g_param_spec_boxed ("border-width",
                                                               "Border width",
                                                               "Border width, in pixels",
-                                                              GTK_TYPE_BORDER, 0));
+                                                              GTK_TYPE_BORDER, 0),
+                                          NULL,
+                                          unpack_border_width,
+                                          pack_border_width);
   gtk_style_properties_register_property (NULL,
                                           g_param_spec_int ("border-radius",
                                                             "Border radius",
index 38850a19e70b4730ced1f7801cb106b2179681be..a1d222ecf5afaba58cf05c4e7f4c910c3a894c57 100644 (file)
@@ -30,7 +30,7 @@ typedef GParameter *     (* GtkStyleUnpackFunc)            (const GValue
                                                             guint                  *n_params);
 typedef void             (* GtkStylePackFunc)              (GValue                 *value,
                                                             GtkStyleProperties     *props,
-                                                            GtkStateFlags           flags);
+                                                            GtkStateFlags           state);
 
 struct _GtkStyleProperty
 {